package com.hspedu.homework;

/**
 * @author DL5O
 * @version 1.0
 */
public class Homework04 {
    public static void main(String[] args) {
        //使用匿名内部类调用CellPhone对象的testWork方法
        Cellphone cellphone = new Cellphone();
        cellphone.testWork(new Calculate() {
            @Override
            public void work() {
                int n1 = 10;
                int n2 = 20;
                System.out.println(n1+ "+" + n2+ "=" + (n1+n2));
            }
        });

    }
}

interface Calculate{
    void work();
}

class Cellphone {
    public void testWork(Calculate calculate){
        calculate.work();//动态绑定机制
    }
}
